package router

import (
	"jgt-oper/src/context"
	"jgt-oper/src/web"

	"github.com/facebookgo/inject"
	"github.com/teambition/gear"
)

// WebDictionaryMap 注册路由映射
func WebDictionaryMap(g *inject.Graph, r *gear.Router) {
	a := new(web.Dictionary)
	err := g.Provide(&inject.Object{Value: a})
	if err != nil {
		panic(err)
	}

	r.Get("/dictionaries/page", context.WrapContext(a.QueryPage))
	r.Get("/dictionaries/data", context.WrapContext(a.QueryTree))
	r.Get("/dictionaries/tree", context.WrapContext(a.QueryShowTree))
	r.Get("/dictionaries/list", context.WrapContext(a.QueryNameList))
	r.Get("/dictionaries/one", context.WrapContext(a.GetByCode))
	r.Get("/dictionaries/:id", context.WrapContext(a.Get))
	r.Post("/dictionaries", context.WrapContext(a.Create))
	r.Put("/dictionaries/:id", context.WrapContext(a.Update))
	r.Put("/dictionaries/:id/up", context.WrapContext(a.MoveUp))
	r.Put("/dictionaries/:id/down", context.WrapContext(a.MoveDown))
	r.Delete("/dictionaries", context.WrapContext(a.DeleteMany))
	r.Delete("/dictionaries/:id", context.WrapContext(a.Delete))
}
